package top.zerozoo.learn.grade.vo;

import top.zerozoo.learn.grade.entity.Major;
import top.zerozoo.learn.grade.entity.Student;
import top.zerozoo.learn.grade.enums.Sex;
import top.zerozoo.learn.grade.factory.ServiceFactory;
import top.zerozoo.learn.grade.service.MajorService;

public class StudentInfo {
    private Integer id;
    private String name;
    private String birthday;
    private String sex;
    private String address;
    private String phone;
    private String idcard;
    private Major major;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getIdcard() {
        return idcard;
    }

    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }

    public Major getMajor() {
        return major;
    }

    public void setMajor(Major major) {
        this.major = major;
    }

    @Override
    public String toString() {
        return "StudentInfo{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", birthday='" + birthday + '\'' +
                ", sex='" + sex + '\'' +
                ", address='" + address + '\'' +
                ", phone='" + phone + '\'' +
                ", idcard='" + idcard + '\'' +
                ", major=" + major +
                '}';
    }

    public static StudentInfo parse(Student student){
        StudentInfo studentInfo = new StudentInfo();
        studentInfo.setId(student.getId());
        studentInfo.setName(student.getName());
        studentInfo.setBirthday(student.getBirthday().toString());
        studentInfo.setSex(Sex.parse(student.getSex()).toString());
        studentInfo.setAddress(student.getAddress());
        studentInfo.setPhone(student.getPhone());
        studentInfo.setIdcard(student.getIdcard());
        if(student.getMajorID()!=null){
            studentInfo.setMajor(ServiceFactory.get(MajorService.class).findById(student.getMajorID()));
        }

        return studentInfo;
    }
}
